<?php

namespace App\Model\Guild;

use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;

/**
 * 公会
 */
class GuildManage extends GuildBase
{
    protected $table = 'guild_manage';

    /**
     * 获取所有公会
     */
    static function getGuilds()
    {
        return self::where(['status' => 1])->orderBy('id', 'desc')->get()->toArray();
    }

    /**
     * 计算公会分成
     */
    static function guildShareIncome($ratio = 0, $totalTurnOver = 0)
    {
        return round($totalTurnOver * $ratio, 1);
    }

    /**
     * 计算主播分成
     */
    static function hostShareIncome($ratio = 0, $totalTurnOver = 0)
    {
        return round($totalTurnOver * $ratio, 1);
    }

    /**
     * 根据登录ID获取公会信息
     */
    static function getInfoByGuildId($guildId = '')
    {
        $data = self::where('guild_id', $guildId)->first();
        return $data ? $data->toArray() : [];
    }

    /**
     * @param $userId
     * @return Builder|Model|object|null
     */
    public function getGuildInfoByUserId($userId)
    {
        return $this->where('user_id', $userId)->first();
    }
}
